<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://www.joda.org/joda/time/tags" prefix="joda" %>

<link href="css/apps/contract/edit.css"  type="text/css"  rel="stylesheet" />
<script type="text/javascript">
template.openTag = '<#';
template.closeTag = '#>';
var gindex = 0;
</script>
<script id="dataLine" type="text/html">
<tr>     
     <input name="beans[<#=index#>].contract.id" type="hidden"  value="<#=contract.id#>"/>
     <input name="beans[<#=index#>].fireDate"    type="hidden"  value="<#=fireDate#>"/>
  <td>
     <span class="label label-info"><#=contract.name#></span>
  </td> 
  <td>
     <input class="codename" readonly="readonly" name="beans[<#=index#>].product.code" value="<#=product.code#>" />
  </td>
  <td>
     <input class="codename" readonly="readonly" name="beans[<#=index#>].product.name" value="<#=product.name#>" />
  </td> 
  <td><input  class="codename" name="beans[<#=index#>].boxes" value="<#=boxes#>" /></td> 
  <td><input  class="codename" name="beans[<#=index#>].batchName" value="<#=batchName#>" /></td> 
  <td><input  class="codename" name="beans[<#=index#>].value" value="<#=value#>" /></td> 
  <td><a href="javascript:;" onclick="removeMe(this)"><img src="${sbase}images/removeMe.gif"/> </a></td>
</tr>
</script>

<div class="input-append">
   <form id="pform">
     <%
        org.joda.time.DateTime dt = org.joda.time.DateTime.now();
        pageContext.setAttribute("ddate", dt.toString("yyyy-MM-dd"));
     %>
     <select name="bean.client.id" id="clients" ></select>    
     <input  name="bean.fireDate" class="datepicker" id="firedate" 
       value="${ddate}"
       readOnly />
     
   </form>
     <button class="btn btn-success" type="button" onclick="showAddDialog()">
       <i class="icon-white icon-plus"></i>
                       添加出库
     </button>
</div>

<table class="table table-bordered table-hover table-striped">
  <thead>
  
  <tr>
    <th>合同号</th>
    <th>产品代码</th>
    <th>产品名称</th>
    <th>批号</th>
    <th>箱数</th>
    <th>数量[万/公斤/KG/M]</th>
    <th>管理</th>
  </tr>
  </thead>
  <form id="dataform">
  <tbody id="pdtBody">
  
  </tbody>
  </form>
  <tfoot>
   <tr>
    <td>
     <button class="btn btn-primary" type="button" onclick="saveAll()">
        <i class="icon-white icon-ok-circle"></i>保存
     </button>
    </td>
   </tr>
  </tfoot>
</table>





<script type="text/javascript">

  $(function(){
	 $("#firedate").datepicker();
	 $("#clients").load('contract/client/contract-client!options') ;
  });
  
    
  function showAddDialog(){
	  var cid = $("#clients").val();	
	  var url="productcomeoutitem/product-comeout-item-prepare?cid="+cid;
	  window.showModalDialog(url,window);
	  
  }
  
  function addLine(data){
	    data.fireDate = $("#firedate").val();
		data.index = gindex++;	
		alert(JSON.stringify(data));
		var line = template.render("dataLine",data);
		$("#pdtBody").append(line);
   }
   function removeMe(self){
	   $(self).parent().parent().remove();
   }

   function saveAll(){
	   var params =  $("#dataform").serialize();   
       $.post('productcomeoutitem/product-comeout-item!creates',params,function(){
    	   createNotify('出库记录保存完毕!');
       })
   }
</script>